﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：CX_BAOBIAOCS实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class CX_BAOBIAOCS
    {
        private decimal? m_dec_i_baobiaoid;

        private decimal? m_dec_i_canshulx;

        private decimal? m_dec_i_xianshisx;

        private decimal m_dec_id;

        private DateTime? m_DT_d_caozuosj;

        private string m_str_s_canshu;

        private string m_str_s_canshumc;

        private string m_str_s_canshuz;

        private string m_str_s_canshuzlx;

        private string m_str_s_caozuor;

        private string m_str_s_miaoshu;

        private string m_str_s_morenz;

        private string m_str_s_shaixuantj;

        private string m_str_s_shujuy;

        /// <summary>
        ///     Sequence
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     报表ID
        /// </summary>
        public decimal? I_BAOBIAOID
        {
            get { return m_dec_i_baobiaoid; }
            set { m_dec_i_baobiaoid = value; }
        }

        /// <summary>
        ///     参数显示顺序
        /// </summary>
        public decimal? I_XIANSHISX
        {
            get { return m_dec_i_xianshisx; }
            set { m_dec_i_xianshisx = value; }
        }

        /// <summary>
        ///     参数类型（非实时: 0:查询;1:筛选;实时无意义)
        /// </summary>
        public decimal? I_CANSHULX
        {
            get { return m_dec_i_canshulx; }
            set { m_dec_i_canshulx = value; }
        }

        /// <summary>
        ///     参数名称（调用时界面显示）
        /// </summary>
        public string S_CANSHUMC
        {
            get { return m_str_s_canshumc; }
            set { m_str_s_canshumc = value; }
        }

        /// <summary>
        ///     参数（存储过程参数名）
        /// </summary>
        public string S_CANSHU
        {
            get { return m_str_s_canshu; }
            set { m_str_s_canshu = value; }
        }

        /// <summary>
        ///     参数值类型
        /// </summary>
        public string S_CANSHUZLX
        {
            get { return m_str_s_canshuzlx; }
            set { m_str_s_canshuzlx = value; }
        }

        /// <summary>
        ///     数据源
        /// </summary>
        public string S_SHUJUY
        {
            get { return m_str_s_shujuy; }
            set { m_str_s_shujuy = value; }
        }

        /// <summary>
        ///     参数值
        /// </summary>
        public string S_CANSHUZ
        {
            get { return m_str_s_canshuz; }
            set { m_str_s_canshuz = value; }
        }

        /// <summary>
        ///     默认值
        /// </summary>
        public string S_MORENZ
        {
            get { return m_str_s_morenz; }
            set { m_str_s_morenz = value; }
        }

        /// <summary>
        ///     筛选表达式
        /// </summary>
        public string S_SHAIXUANTJ
        {
            get { return m_str_s_shaixuantj; }
            set { m_str_s_shaixuantj = value; }
        }

        /// <summary>
        ///     参数描述(调用时提示)
        /// </summary>
        public string S_MIAOSHU
        {
            get { return m_str_s_miaoshu; }
            set { m_str_s_miaoshu = value; }
        }

        /// <summary>
        ///     操作人
        /// </summary>
        public string S_CAOZUOR
        {
            get { return m_str_s_caozuor; }
            set { m_str_s_caozuor = value; }
        }

        /// <summary>
        ///     操作时间
        /// </summary>
        public DateTime? D_CAOZUOSJ
        {
            get { return m_DT_d_caozuosj; }
            set { m_DT_d_caozuosj = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class CX_BAOBIAOCSProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public CX_BAOBIAOCSProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据CX_BAOBIAOCS实体添加或者修改CX_BAOBIAOCS信息
        /// </summary>
        public bool InsertOrUpdate(CX_BAOBIAOCS CX_BAOBIAOCS, OracleTransaction Transaction)
        {
            if (CX_BAOBIAOCS.ID == 0)
                InsertCX_BAOBIAOC(CX_BAOBIAOCS, Transaction);
            else
                UpdateCX_BAOBIAOC(CX_BAOBIAOCS, Transaction);
            return CX_BAOBIAOCS.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据CX_BAOBIAOCS实体添加或修改CX_BAOBIAOCS信息
        /// </summary>
        public bool InsertOrUpdate(CX_BAOBIAOCS CX_BAOBIAOCS)
        {
            return InsertOrUpdate(CX_BAOBIAOCS, null);
        }


        /// <summary>
        ///     根据CX_BAOBIAOCS主键删除CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteCX_BAOBIAOC(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelCX_BAOBIAOC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据CX_BAOBIAOCS主键删除CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteCX_BAOBIAOC(decimal ID)
        {
            return DeleteCX_BAOBIAOC(ID, null);
        }

        /// <summary>
        ///     根据条件删除CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteCX_BAOBIAOCsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelCX_BAOBIAOCsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteCX_BAOBIAOCsDynamic(string WhereClause)
        {
            return DeleteCX_BAOBIAOCsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据CX_BAOBIAOCS主键选择CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>CX_BAOBIAOCS信息</returns>
        public CX_BAOBIAOCS SelectCX_BAOBIAOC(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelCX_BAOBIAOC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var CX_BAOBIAOCS = PopulateCX_BAOBIAOCS(rd);
                rd.Close();
                return CX_BAOBIAOCS;
            }
            return null;
        }

        /// <summary>
        ///     根据CX_BAOBIAOCS主键选择CX_BAOBIAOCS信息
        /// </summary>
        /// <returns>CX_BAOBIAOCS信息</returns>
        public CX_BAOBIAOCS SelectCX_BAOBIAOC(decimal ID)
        {
            return SelectCX_BAOBIAOC(ID, null);
        }

        /// <summary>
        ///     选择所有CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有CX_BAOBIAOCS信息</returns>
        public DataTable SelectCX_BAOBIAOCsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelCX_BAOBIAOCsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有CX_BAOBIAOCS信息
        /// </summary>
        /// <returns>所有CX_BAOBIAOCS信息</returns>
        public DataTable SelectCX_BAOBIAOCsAll()
        {
            return SelectCX_BAOBIAOCsAll(null);
        }

        /// <summary>
        ///     根据条件选择CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>CX_BAOBIAOCS信息</returns>
        public DataTable SelectCX_BAOBIAOCsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelCX_BAOBIAOCsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>CX_BAOBIAOCS信息</returns>
        public DataTable SelectCX_BAOBIAOCsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectCX_BAOBIAOCsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>CX_BAOBIAOCS信息</returns>
        public DataTable SelectCX_BAOBIAOCsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelCX_BAOBIAOCsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择CX_BAOBIAOCS信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>CX_BAOBIAOCS信息</returns>
        public DataTable SelectCX_BAOBIAOCsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectCX_BAOBIAOCsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新CX_BAOBIAOCS字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateCX_BAOBIAOCsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdCX_BAOBIAOCDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新CX_BAOBIAOCS字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateCX_BAOBIAOCsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateCX_BAOBIAOCsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertCX_BAOBIAOC(CX_BAOBIAOCS CX_BAOBIAOCS, OracleTransaction Transaction)
        {
            var spName = "CS_InsCX_BAOBIAOC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = CX_BAOBIAOCS.I_BAOBIAOID;
            storedParams[1].Value = CX_BAOBIAOCS.I_XIANSHISX;
            storedParams[2].Value = CX_BAOBIAOCS.I_CANSHULX;
            storedParams[3].Value = CX_BAOBIAOCS.S_CANSHUMC;
            storedParams[4].Value = CX_BAOBIAOCS.S_CANSHU;
            storedParams[5].Value = CX_BAOBIAOCS.S_CANSHUZLX;
            storedParams[6].Value = CX_BAOBIAOCS.S_SHUJUY;
            storedParams[7].Value = CX_BAOBIAOCS.S_CANSHUZ;
            storedParams[8].Value = CX_BAOBIAOCS.S_MORENZ;
            storedParams[9].Value = CX_BAOBIAOCS.S_SHAIXUANTJ;
            storedParams[10].Value = CX_BAOBIAOCS.S_MIAOSHU;
            storedParams[11].Value = CX_BAOBIAOCS.S_CAOZUOR;
            storedParams[12].Value = CX_BAOBIAOCS.D_CAOZUOSJ;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            CX_BAOBIAOCS.ID = Convert.ToInt32(storedParams[13].Value);
            return result;
        }

        private bool UpdateCX_BAOBIAOC(CX_BAOBIAOCS CX_BAOBIAOCS, OracleTransaction Transaction)
        {
            var spName = "CS_UpdCX_BAOBIAOC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = CX_BAOBIAOCS.I_BAOBIAOID;
            storedParams[1].Value = CX_BAOBIAOCS.I_XIANSHISX;
            storedParams[2].Value = CX_BAOBIAOCS.I_CANSHULX;
            storedParams[3].Value = CX_BAOBIAOCS.S_CANSHUMC;
            storedParams[4].Value = CX_BAOBIAOCS.S_CANSHU;
            storedParams[5].Value = CX_BAOBIAOCS.S_CANSHUZLX;
            storedParams[6].Value = CX_BAOBIAOCS.S_SHUJUY;
            storedParams[7].Value = CX_BAOBIAOCS.S_CANSHUZ;
            storedParams[8].Value = CX_BAOBIAOCS.S_MORENZ;
            storedParams[9].Value = CX_BAOBIAOCS.S_SHAIXUANTJ;
            storedParams[10].Value = CX_BAOBIAOCS.S_MIAOSHU;
            storedParams[11].Value = CX_BAOBIAOCS.S_CAOZUOR;
            storedParams[12].Value = CX_BAOBIAOCS.D_CAOZUOSJ;
            storedParams[13].Value = CX_BAOBIAOCS.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private CX_BAOBIAOCS PopulateCX_BAOBIAOCS(IDataReader dr)
        {
            var CX_BAOBIAOCS = new CX_BAOBIAOCS();
            CX_BAOBIAOCS.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            CX_BAOBIAOCS.I_BAOBIAOID = dr["I_BAOBIAOID"] == DBNull.Value ? null : (decimal?) dr["I_BAOBIAOID"];
            CX_BAOBIAOCS.I_XIANSHISX = dr["I_XIANSHISX"] == DBNull.Value ? null : (decimal?) dr["I_XIANSHISX"];
            CX_BAOBIAOCS.I_CANSHULX = dr["I_CANSHULX"] == DBNull.Value ? null : (decimal?) dr["I_CANSHULX"];
            CX_BAOBIAOCS.S_CANSHUMC = dr["S_CANSHUMC"] == DBNull.Value ? null : (string) dr["S_CANSHUMC"];
            CX_BAOBIAOCS.S_CANSHU = dr["S_CANSHU"] == DBNull.Value ? null : (string) dr["S_CANSHU"];
            CX_BAOBIAOCS.S_CANSHUZLX = dr["S_CANSHUZLX"] == DBNull.Value ? null : (string) dr["S_CANSHUZLX"];
            CX_BAOBIAOCS.S_SHUJUY = dr["S_SHUJUY"] == DBNull.Value ? null : (string) dr["S_SHUJUY"];
            CX_BAOBIAOCS.S_CANSHUZ = dr["S_CANSHUZ"] == DBNull.Value ? null : (string) dr["S_CANSHUZ"];
            CX_BAOBIAOCS.S_MORENZ = dr["S_MORENZ"] == DBNull.Value ? null : (string) dr["S_MORENZ"];
            CX_BAOBIAOCS.S_SHAIXUANTJ = dr["S_SHAIXUANTJ"] == DBNull.Value ? null : (string) dr["S_SHAIXUANTJ"];
            CX_BAOBIAOCS.S_MIAOSHU = dr["S_MIAOSHU"] == DBNull.Value ? null : (string) dr["S_MIAOSHU"];
            CX_BAOBIAOCS.S_CAOZUOR = dr["S_CAOZUOR"] == DBNull.Value ? null : (string) dr["S_CAOZUOR"];
            CX_BAOBIAOCS.D_CAOZUOSJ = dr["D_CAOZUOSJ"] == DBNull.Value ? null : (DateTime?) dr["D_CAOZUOSJ"];
            return CX_BAOBIAOCS;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion